import Vue from 'vue';
import App from '@/App';
import store from '@/store';

// 引入 uView UI
import uView from 'uview-ui';
Vue.use(uView);

Vue.config.productionTip = false;

// 引入全局工具函数
import * as utils from '@/utils/index';
Vue.prototype.$utils = utils;

// 引入请求封装
import request from '@/utils/request';
Vue.prototype.$request = request;

// 引入全局配置
import config from '@/config/index';
Vue.prototype.$config = config;

// ...其他代码保持不变

// 全局混入
Vue.mixin({
  methods: {
    // 显示消息提示框
    showToast(title, icon = 'none') {
      uni.showToast({
        title,
        icon
      });
    },
    // 显示模态弹窗
    showModal(content, title = '提示', showCancel = true) {
      return new Promise((resolve, reject) => {
        uni.showModal({
          title,
          content,
          showCancel,
          success: function(res) {
            if (res.confirm) {
              resolve(true);
            } else if (res.cancel) {
              resolve(false);
            }
          },
          fail: function(err) {
            reject(err);
          }
        });
      });
    }
  }
});

App.mpType = 'app';

const app = new Vue({
  store,
  ...App
});
app.$mount();